<template>
  <div class="app-container">
    <div class="formDiv">
      <el-form ref="form" :inline="true" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="姓名">
              <el-input v-model="form.realname" placeholder="请输入姓名" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="手机号">
              <el-input v-model="form.username" placeholder="请输入手机号" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="生效时间">
              <el-date-picker
                value-format="yyyy-MM-dd "
                v-model="dates"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              >></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="认购分公司">
              <el-select v-model="form.subscriptionId" placeholder="请选择" clearable filterable>
                <el-option
                  v-for="(item, index) in provinceOfficeList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24"></el-col>
          <el-col :span="6">
            <el-form-item label="推荐渠道">
              <el-select v-model="form.recommendId" placeholder="请选择" clearable filterable>
                <el-option
                  v-for="item in payOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="table" v-loading="tableLoading">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" label="序列" align="center" :index="table_index" width="50"></el-table-column>
        <el-table-column prop="realname" label="姓名" />
        <el-table-column prop="username" label="手机号">
          <template slot-scope="scope">
            <div>{{scope.row.username | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="area" label="地区" />
        <el-table-column prop="subscriptionName" label="认购分公司" />
        <el-table-column prop="subscriptionAmount" label="认购金额" />
        <el-table-column prop="recommendName" label="推荐渠道" />
        <el-table-column prop="status" label="审核状态" />
        <el-table-column prop="signType" label="签约类型" />
        <el-table-column prop="createBy" label="录入时间" />
        <el-table-column prop="examineTime" label="生效时间" />
        <el-table-column prop="assessmentTime" label="考核截止时间">
          <template slot-scope="scope">
            <!-- <span
              :class="((new Date(scope.row.assessmentTime).getTime()+7)> Date.now()|(new Date(scope.row.assessmentTime).getTime())> Date.now())&scope.row.directServerCount<300?'col_red':''"
            >{{scope.row.assessmentTime}}</span>-->
            <span :class="scope.row.red==0?'':'col_red'">{{scope.row.assessmentTime}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="directServerCount" label="累计推荐门店数" />
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="toRoutes('LCadminInfo',scope.row.id)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagesCon">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="form.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="form.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import { getList } from "@/api/LCadministration";
import { companyList } from "@/api/branchOfficeDropDown";
import { provinceOfficeList } from "@/api/provinceOfficeList";
export default {
  data() {
    return {
      tableLoading: false,
      tableData: [],
      total: 0,
      form: {
        pageNum: 1,
        pageSize: 10,
        realname: null,
        usename: null,
        examineTimeStart: null,
        examineTimeEnd: null,
        subscriptionId: null,
        recommendId: null
      },
      dates: [],
      payOption: [],
      provinceOfficeList: []
    };
  },
  mounted() {
    this.getList(this.form);
    this.getCompanyList();
  },
  methods: {
    // 成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    // 路由跳转
    toRoutes(e, id) {
      const route = { name: e, query: { id: id } };
      this.$router.push(route);
    },
    // 获取分公司列表
    async getCompanyList() {
      companyList()
        .then(res => {
          const resData = res.data.data;
          const newData = [];
          resData.forEach(e => {
            newData.push({
              value: e.id,
              label: e.name
            });
          });
          this.payOption = newData;
        })
        .catch(error => {
          this.$message.error(error);
        });
      const res = await provinceOfficeList({ types: [0] });
      if (res.data.code == 0) {
        this.provinceOfficeList = res.data.data;
      } else {
        this.$message.error(res.data.msg);
      }
    },
    // 列表数据获取
    getList(e) {
      this.tableLoading = true;
      const datas = e;
      getList(datas)
        .then(res => {
          console.log(res);
          if (!res.data.code) {
            // console.log(res)
            this.tableData = res.data.data.list;
            this.total = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1;
      this.getList(this.form);
      // console.log(JSON.stringify(this.form))
    },
    handleSizeChange(val) {
      this.form.pageNum = 1;
      this.form.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList();
    },
    table_index(index) {
      return (this.form.pageNum - 1) * this.form.pageSize + index + 1;
    }
  },
  watch: {
    dates(val) {
      this.form.examineTimeStart = this.dates ? this.dates[0] : "";
      this.form.examineTimeEnd = this.dates ? this.dates[1] : "";
    },
    "form.subscriptionId"(val) {
      console.log(val);
      this.form.subscriptionId = val == "" ? null : val;
    },
    "form.recommendId"(val) {
      console.log(val);
      this.form.recommendId = val == "" ? null : val;
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
.col_red {
  color: red;
}
</style>